﻿//-----------------------------------------------
// RedditSharp (Reddit#)
//
// Copyright (c) 2011 - 2012
// - Angelo Geels <angelo@angelog.nl>
//-----------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RedditSharp
{
    public class RedditComment : RedditThing
    {
        public string Author;
        public string Body;

        public RedditComment[] Children;

        /// <summary>
        /// Parses a reddit comment based on the Hashtable received.
        /// </summary>
        /// <param name="CommentData">The comment data in Hashtable form</param>
        /// <returns>The RedditComment</returns>
        public static RedditComment Parse(Hashtable CommentData)
        {
            RedditComment ret = new RedditComment();

            ret.ID = (string)CommentData["id"];
            ret.FullID = (string)CommentData["name"];

            ret.Subreddit = (string)CommentData["subreddit"];

            ret.Author = (string)CommentData["author"];
            ret.Body = (string)CommentData["body"];

            ret.MyScore = CommentData["likes"] == null ? 0 : (bool)CommentData["likes"] == true ? 1 : -1;
            ret.Upvotes = (int)(double)CommentData["ups"];
            ret.Downvotes = (int)(double)CommentData["downs"];
            ret.Score = ret.Upvotes - ret.Downvotes;

            return ret;
        }
    }
}
